<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%@include file="common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String subDeviceId=request.getParameter("deviceId");
%>

<!DOCTYPE>
<html style="font-size: 100px;">
  <head>
    <title>智慧消防</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/common.css" type="text/css"></link>
	  <link href="<%=request.getContextPath()%>/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript">
    	$(function(){
            var subDeviceId = $.trim($('#subDeviceId').val());
            if(subDeviceId != "null"){
                if(subDeviceId.indexOf('KG')){
                    $('#subDeviceType').val("客舱固定灭火系统");
                }else if(subDeviceId.indexOf('PB')){
                    $('#subDeviceType').val("破玻器");
                }else if(subDeviceId.indexOf('SD')){
                    $('#subDeviceType').val("手动火灾报警按钮");
                }else if(subDeviceId.indexOf('SG')){
                    $('#subDeviceType').val("声光报警器");
                }else if(subDeviceId.indexOf('HZ')){
                    $('#subDeviceType').val("火灾探测器");
                }else if(subDeviceId.indexOf('WD')){
                    $('#subDeviceType').val("温度探测器");
                }else if(subDeviceId.indexOf('CX')){
                    $('#subDeviceType').val("超细干粉自动灭火装置");
                }else if(subDeviceId.indexOf('DC')){
                    $('#subDeviceType').val("电池箱专用灭火装置");
                }
            }
  			getVehicle();
    	});
    	
    	function getVehicle(){
    		var url = '${linkPath}smartfire/wx/vehicle/getList';
    		$.ajax({
		        url:url,
		        type: 'get',
		        data: {
                    'userId' : userId
				},
                beforeSend: function(request) {
                    request.setRequestHeader("ACCESS-TOKEN", token);
                },
		        success: function(res){
		            var vehicleDevice = res.obj;
		            var deviceId = $("#deviceId");
		            for(var i=0;i<vehicleDevice.length;i++){
                        deviceId.append('<option value="'+vehicleDevice[i].deviceId+'">'+vehicleDevice[i].deviceName+'</option>');
		            }
		        },
		        error: function(error){
		            console.log(error)
		        }
		    });
    	}
    
  		function saveDeviceInfo(){
  			var subDeviceId = $.trim($('#subDeviceId').val());
  			var deviceId = $.trim($('#deviceId').val());
            if($.trim(deviceId)==""){
                $('#deviceId').focus();
                return false;
            }
  			var deviceName = $('#deviceName').val();
  			if($.trim(deviceName)==""){
  				$('#deviceName').focus();
                $('span.deviceName').html("子设备名称不能为空");
  				return false;
  			}
  			var subDeviceType = $('#subDeviceType').val();
            if($.trim(subDeviceType)==""){
                $('#subDeviceType').focus();
                $('span.subDeviceType').html("请选择子设备类型");
                return false;
            }

  			var url = '${linkPath}smartfire/wx/vehicle/save';
  			var data = JSON.stringify({
  				'deviceId': deviceId,
  				'subDeviceId': subDeviceId,
  				'deviceName': deviceName,
  				'deviceType' : subDeviceType
  			});
  		
  			$.ajax({
		        url:url,
		        type: 'post',
		        data: data,
                contentType: "application/json;charset=utf-8",
                beforeSend: function(request) {
                    request.setRequestHeader("ACCESS-TOKEN", token);
                },
		        success: function(res){
		           if(res.success){
		           		myAlert("添加成功");
                       setTimeout(function(){
                           location.href ='<%=path %>/login/main.jsp';
                       },1000);
		           }else{
                       myAlert(res.msg);
                   }
		        },
		        error: function(error){
		            console.log(error);
		        }
		    });
  		
  		}
    </script>
  </head>
  
  <body>
  <div class="bar">
	  <div class="naviBar">
		  <img onclick="javascript:history.back(-1);" src="<%=path %>/images/common/return.png" alt="">
		  <span>车载子设备</span>
	  </div>
	  <div class="col-sm-6" style="margin-top: 0.40rem;padding-bottom: 0.4rem">
		  <div class="ibox float-e-margins" style="padding-top: 10px;">
			  <div class="ibox-content" style="display: block;">
				  <%-- <form class="form-horizontal m-t" id="signupForm" novalidate="novalidate">--%>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">子设备ID：</label>
					  <div class="col-sm-8">
						  <input id="subDeviceId" name="subDeviceId" class="form-control" type="text" value ="<%=subDeviceId %>" readonly>
						  <span class="help-block m-b-none deviceId"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">车载设备</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b" name="deviceId" id="deviceId">
							  <option value="">--请选择--</option>
						  </select>
						  <span class="help-block m-b-none deviceId"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">子设备名称：</label>
					  <div class="col-sm-8">
						  <input id="deviceName" name="deviceName" class="form-control" type="text" placeholder="子设备名称">
						  <span class="help-block m-b-none deviceName"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">NB终端设备</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b" id="subDeviceType" name="subDeviceType">
							  <option value="">--请选择子设备类型--</option>
							  <option value="11">客舱固定灭火系统</option>
							  <option value="12">破玻器</option>
							  <option value="13">手动火灾报警按钮</option>
							  <option value="14">声光报警器</option>
							  <option value="15">火灾探测器</option>
							  <option value="16">温度探测器</option>
							  <option value="17">超细干粉自动灭火装置</option>
							  <option value="18">电池箱专用灭火装置</option>
							  <%--<option value="19">安全带集中解锁系统</option>--%>
							  <%--<option value="20">学生安全巡视系统</option>--%>
							  <%--<option value="21">逃生引导系统</option>--%>
						  </select>
						  <span class="help-block m-b-none subDeviceType"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group" style="padding-top: 10px">
					  <div class="col-sm-8 col-sm-offset-3">
						  <button class="btn btn-primary" style="width: 100%"  onclick="saveDeviceInfo()">提交</button>
					  </div>
				  </div>
				  <%-- </form>--%>
			  </div>
		  </div>
	  </div>
  </div>
  </body>
</html>
